package com.reservation.service.impl;

import com.reservation.dto.admin.manage.ReceiveId;
import com.reservation.mapper.AdminHomeMapper;
import com.reservation.mapper.AdminManageMapper;
import com.reservation.service.AdminManageService;
import com.reservation.utils.CurrentHolderUtil;
import com.reservation.vo.admin.rmanageuser.UserList;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@Slf4j
public class AdminManageServiceImpl implements AdminManageService {

    @Autowired
    private AdminManageMapper adminManageMapper;

    @Override
    public List<UserList> getUserList() {

        String userId = String.valueOf(CurrentHolderUtil.getCurrentId());

        List<UserList> list = adminManageMapper.getUserList();
        list.forEach(user -> {
            switch (user.getRole()) {
                case "ADMIN":
                    user.setRole("管理员");
                    break;
                case "USER":
                    user.setRole("用户");
                    break;
                case "STAFF":
                    user.setRole("员工");
                    break;
            }
            switch (user.getStatus()) {
                case "0":
                    user.setStatus("待审核");
                    break;
                case "1":
                    user.setStatus("正常");
                    break;
                case "2":
                    user.setStatus("已冻结");
                    break;
            }
        });

        list.removeIf(user -> user.getId().equals(userId));
        return list;
    }

    @Override
    public boolean updateStates1(ReceiveId receiveId) {

        return adminManageMapper.updateStates1(receiveId) > 0;
    }

    @Override
    public boolean updateStates3(ReceiveId receiveId) {

        return adminManageMapper.updateStates3(receiveId) > 0;
    }

    @Override
    public boolean updateStates2(ReceiveId receiveId) {

        return adminManageMapper.updateStates2(receiveId) > 0;
    }
}
